package com.example.myapplication.Adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.MainActivity;
import com.example.myapplication.R;
import com.example.myapplication.bean.Weather15DayBean;

import java.util.ArrayList;
import java.util.List;

public class RecyclerAdapter2 extends RecyclerView.Adapter<RecyclerAdapter2.ViewHolder> {
    private List<Weather15DayBean> list;
    private Context context;


    public RecyclerAdapter2(List<Weather15DayBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycleriew2, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);

        return viewHolder;
    }

    @Override
    public  void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvPop.setText(String.valueOf(list.get(position).getPop()));
        holder.tvPredictDate.setText(String.valueOf(list.get(position).getPredictDate()));
        holder.tvConditionDay.setText(String.valueOf(list.get(position).getConditionDay()));
        holder.tvTempDay.setText(String.valueOf(list.get(position).getTempDay()));
        String conditionIdDay = list.get(position).getConditionIdDay();
        int con = Integer.parseInt(conditionIdDay);


        int imageResource = context.getResources().getIdentifier("@drawable/ic" + conditionIdDay, null, context.getPackageName());
        Drawable res = context.getResources().getDrawable(imageResource);
         holder.tvConditionIdDay.setImageDrawable(res);




    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvPredictDate;
        private ImageView tvConditionIdDay;
        private TextView tvTempDay;
        private TextView tvConditionDay;
        private TextView textView4;
        private TextView tvPop;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);


            tvPredictDate = (TextView) itemView.findViewById(R.id.tv_predictDate);
            tvConditionIdDay = itemView.findViewById(R.id.tv_conditionIdDay);
            tvTempDay = (TextView) itemView.findViewById(R.id.tv_tempDay);
            tvConditionDay = (TextView) itemView.findViewById(R.id.tv_conditionDay);
            textView4 = (TextView) itemView.findViewById(R.id.textView4);
            tvPop = (TextView) itemView.findViewById(R.id.tv_pop);
        }

    }
}